package com.colin.util.util;

import java.util.concurrent.CountDownLatch;

public class MutlThreadTest {
    /**
     * 每次并发线程数
     */
    private static final Integer THREAD_NUMS = 5;
    /**
     * 执行次数
     */
    private static final Integer TIMES = 1;
    /**
     * 每次之间的时间间隔（ms）
     */
    private static final Integer SLEEP = 1000;

    public static void main(String[] args) {
        startTest();
    }

    public static void startTest(){
        for(int i = 0; i< TIMES; i++){
            try{
                mutiThreadCounter();
                Thread.sleep(SLEEP);
            }catch (Exception e){
                e.printStackTrace();
            }
        }
        toWait();
    }

    private static void mutiThreadCounter() throws Exception{
        final CountDownLatch cdl=new CountDownLatch(1);
        for (int i = 0; i < THREAD_NUMS; i++) {
            final long num = i;
            ThreadPool.putThread(new Runnable() {
                @Override
                public void run() {
                    try {
                        cdl.await();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }

                    //在此处编写需要测试的接口
                    toTest(num);

                }
            });
        }
        cdl.countDown();
    }

    private static void toWait(){
        try {
            Thread.sleep(5*60*1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

    private static void toTest(long num){
        System.out.println("1111111111111" + num);
    }

}
